#!/bin/sh

# Test basic control protocol info commands. See basic_versions.input and
# basic_versions.output files for commands and expected results.

BASEDIR="`dirname "${0}"`/.."
. "${BASEDIR}/functions"

BV_LOGFILE=basic_versions.rlog
BV_TLFILE="_${BV_LOGFILE}"

__beforeexit_cleanup()
{
  if [ ! -z "${TMP_PIDFILE}" ]
  then
    rtpproxy_stop TERM
  fi
  if [ -f ${BV_TLFILE} ]
  then
    cat ${BV_TLFILE} >>${BV_LOGFILE}
    rm ${BV_TLFILE}
  fi
}

truncate -s 0 ${BV_LOGFILE}
for socket in ${RTPP_TEST_SOCKETS}
do
  if [ "${socket}" = "stdio:" ]
  then
    ${RTPPROXY} -f -s "${socket}" < $BASEDIR/basic_versions/basic_versions.input 2>>${BV_LOGFILE} | \
      ${DIFF} ${BASEDIR}/basic_versions/basic_versions.output -
    report "basic_versions on ${socket}"
  else
    RTPP_SOCKFILE="${socket}" RTPP_OUTFILE="basic_versions.rout" RTPP_LOGFILE="${BV_TLFILE}" rtpproxy_start
    report "rtpproxy start on ${socket}"
    ${RTPP_QUERY} -t 10  -b -s "${socket}" \
      -S "${TOP_BUILDDIR}/python/sippy_lite" -i $BASEDIR/basic_versions/basic_versions.input -o basic_versions.qout
    report "rtpp_query on ${socket}"
    rtpproxy_stop HUP
    report "rtpproxy stop (SIGHUP) on ${socket}"
    cat basic_versions.qout basic_versions.rout | ${DIFF} ${BASEDIR}/basic_versions/basic_versions.output -
    report "basic_versions on ${socket}"
    cat ${BV_TLFILE} >>${BV_LOGFILE}
    rm ${BV_TLFILE}
  fi
done
